<?php
/**
 * 周舟 hzboye010@163.com
 * addby sublime snippets
 * Mmz Winner log Api
 */
namespace app\shop\api;
use app\common\api\BaseApi;
use app\shop\model\MmzApplyPepole;

class MmzApplyPepoleApi extends BaseApi{

  const ADD      = "shop/MmzApplyPepoleApi/add";
  const SAVE     = "shop/MmzApplyPepoleApi/save";
  const COUNT    = "shop/MmzApplyPepoleApi/count";
  const GET_INFO = "shop/MmzApplyPepoleApi/getInfo";
  const SET_INC  = "shop/MmzApplyPepoleApi/setInc";
  /*private */
  const QUERY_COUNT  = "shop/MmzApplyPepoleApi/queryCount";

  protected function _init(){
		$this->model = new MmzApplyPepole();
	}
	/**
	 * query
	 * @param 查询条件|null $map
	 * @param array|分页参数 $page
	 * @param bool|排序参数 $order
	 * @param bool|点击分页时带参数 $params
	 * @param bool $fields
	 * @return array
	 * @internal param 查询条件 $map
	 * @internal param 分页参数 $page
	 * @internal param 排序参数 $order
	 * @internal param 点击分页时带参数 $params
	 */
	public function queryCount($map = null, $page = ['page'=>1,'size'=>10], $order = false, $params = false, $fields = false) {
		$start = (intval($page['page'])-1)*$page['size'];
		$query = $this->model->alias('a')->join('common_member as m on m.uid=a.uid','left');
		if(!empty($map)) $query = $query->where($map);
		if(false !== $order) $query = $query->order($order);
		if(false !== $fields) $query = $query->field($fields);
		$list = $query -> limit($start,$page['size']) -> select();

		if (false === $list) {
		  $error = $this -> model -> getDbError();
		  return $this -> apiReturnErr($error);
		}
		$count = $this -> model ->alias('a')-> where($map) -> count();
		return $this -> apiReturnSuc(["count" => $count, "list" => $list]);
	}
}